/************************************************************************************
* PlayerWidget.h                                                                    *
*                                                                                   *
* Copyright (C) 2011 Varuna L Amachi                                                *
*                                                                                   *
* This program is free software; you can redistribute it and/or modify              *
* it under the terms of the GNU General Public License as published by              *
* the Free Software Foundation; either version 2 of the License, or any             *
* later version.                                                                    *
*                                                                                   *
* This program is distributed in the hope that it will be useful, but               *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY        *
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for       *
* more details. You should have received a copy of the GNU General Public           *
* License along with this program; if not, write to the Free Software Foundation,   *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                       *
*                                                                                   *
*************************************************************************************/


#ifndef PLAYERWIDGET_H
#define PLAYERWIDGET_H

#include <QWidget>
#include <phonon/audiooutput.h>
#include <phonon/seekslider.h>
#include <phonon/mediaobject.h>
#include <phonon/volumeslider.h>
#include <phonon/backendcapabilities.h>
#include <QList>
#include <QLabel>
#include <QPushButton>

#include "common/MediaItem.h"
#include "interfaces/Player.h"
#include "SongInfoDisplayWidget.h"



QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE


class PlayerWidget : public QWidget, public Yamp::Player
{
    Q_OBJECT

public:
    explicit PlayerWidget(QWidget *parent = 0);
    ~PlayerWidget();
    Phonon::State state();
    bool isPlayEnabled();
    bool isStopEnabled();
    bool isPrevEnabled();
    bool isNextEnabled();
    MediaItem* currentTrack();
    void dragEnterEvent(QDragEnterEvent * event);
    void dropEvent(QDropEvent *event);

private slots:
    void stateChanged(Phonon::State newState, Phonon::State oldState);
    void notifyPlayStarted();
    void notifyPlayFinished();
    void notifyRatingChanged(MediaRating rating);
    void addListener(IPlayerListener *listenre);

public slots:
    void setPlayEnabled(bool value);
    void setStopEnabled(bool value);
    void setPrevEnabled(bool value);
    void setNextEnabled(bool value);
    void setSource(MediaItem* source);
    void stopAndClear();
    void seekForword();
    void seekBackword();
    void currentItemChanged(MediaItem* item);

signals:
    void yampSolo(bool val);
    void nextClicked();
    void prevClicked();
    void finished();
    void contentDropped(QList<QUrl>);
    void needSomethingToPlay();
    void playerStateChanged(Phonon::State newState, Phonon::State oldState);

private:
    void setupActions();
    void setupMenus();
    void setupUi();
    void setupStyle();
    void updateMediaInfo();

    Phonon::VolumeSlider *m_volumeSlider;
    Phonon::SeekSlider *m_seekSlider;
    SongInfoDisplayWidget* m_infoArea;
    QPushButton* m_yampButton;

    Phonon::MediaObject *m_mediaObject;
    Phonon::AudioOutput *m_audioOutput;
    MediaItem* m_source;

    QAction *m_playAction;
    QAction *m_pauseAction;
    QAction *m_stopAction;
    QAction *m_nextAction;
    QAction *m_previousAction;

    QList<IPlayerListener*> m_listeners;
    QString m_scrollingName;
};

#endif // PLAYERWIDGET_H
